$(function() {
    //地址前缀
    var path = "${pageContext.request.contextPath}";
    //富文本编辑器（免费内容）
    var ue1 = UE.getEditor('freeContent');
    /*ue1.ready(function() {
        //不可编辑
        ue1.setDisabled();
    });*/
    //富文本编辑器（收费内容）
    var ue2 = UE.getEditor('chargeContent');
    /*ue2.ready(function() {
        //不可编辑
        ue2.setDisabled();
    });*/

    $("#articleState").on("change", function () {
        var articleState = $("#articleState").val();
        if (articleState == '2') {//审核不通过
            $("#auditReasonTd").html("<font color=\"red\">*</font>审核理由：");
        } else {//审核通过
            $("#auditReasonTd").html("审核理由：");
        }
    });

});

//保存
function save() {

    //审核状态
    if($("#articleState").val() == ""){
        $("#articleStateSelect").tips({
            side: 3,
            msg: '选择审核状态',
            bg: '#AE81FF',
            time: 2
        });
        $("#articleState").focus();
        return false;
    }

    //审核理由
    var articleState = $("#articleState").val();
    if (articleState == '2') {//审核不通过
        if ($("#auditReason").val()=="") {
            $("#auditReason").tips({
                side:3,
                msg:'请输入审核理由',
                bg:'#AE81FF',
                time:2
            });
            $("#auditReason").focus();
            return false;
        }
    }

    $("#form").submit();
    $("#zhongxin").hide();
    $("#zhongxin2").show();

}

$(function() {
    //下拉框
    if(!ace.vars['touch']) {
        $('.chosen-select').chosen({allow_single_deselect:true});
        $(window)
            .off('resize.chosen')
            .on('resize.chosen', function() {
                $('.chosen-select').each(function() {
                    var $this = $(this);
                    $this.next().css({'width': $this.parent().width()});
                });
            }).trigger('resize.chosen');
        $(document).on('settings.ace.chosen', function(e, event_name, event_val) {
            if(event_name != 'sidebar_collapsed') return;
            $('.chosen-select').each(function() {
                var $this = $(this);
                $this.next().css({'width': $this.parent().width()});
            });
        });
        $('#chosen-multiple-style .btn').on('click', function(e){
            var target = $(this).find('input[type=radio]');
            var which = parseInt(target.val());
            if(which == 2) $('#form-field-select-4').addClass('tag-input-style');
            else $('#form-field-select-4').removeClass('tag-input-style');
        });
    }
});
